import { createSlice } from '@reduxjs/toolkit'

interface SecurityState {
  alerts: any[]
  cameras: any[]
  accessLogs: any[]
  loading: boolean
  error: string | null
}

const initialState: SecurityState = {
  alerts: [],
  cameras: [],
  accessLogs: [],
  loading: false,
  error: null,
}

const securitySlice = createSlice({
  name: 'security',
  initialState,
  reducers: {
    setAlerts: (state, action) => {
      state.alerts = action.payload
    },
    addAlert: (state, action) => {
      state.alerts.unshift(action.payload)
    },
    setCameras: (state, action) => {
      state.cameras = action.payload
    },
    setAccessLogs: (state, action) => {
      state.accessLogs = action.payload
    },
  },
})

export const { setAlerts, addAlert, setCameras, setAccessLogs } = securitySlice.actions
export default securitySlice.reducer
